PREFIX?=/usr/local
VERSION=$(shell git describe)

FILES="$(DESTDIR)/$(PREFIX)/bin/eizelle" \
"$(DESTDIR)/$(PREFIX)/share/appdata/eizelle.appdata.xml" \
"$(DESTDIR)/$(PREFIX)/share/applications/eizelle.desktop" \
"$(DESTDIR)/$(PREFIX)/share/glib-2.0/schemas/org.gnome.eizelle.gschema.xml" \
"$(DESTDIR)/$(PREFIX)/share/help/C/eizelle/birth-control.page" \
"$(DESTDIR)/$(PREFIX)/share/help/C/eizelle/conception.page" \
"$(DESTDIR)/$(PREFIX)/share/help/C/eizelle/index.page" \
"$(DESTDIR)/$(PREFIX)/share/help/C/eizelle/introduction.page" \
"$(DESTDIR)/$(PREFIX)/share/help/C/eizelle/menstrual-cycle.page" \
"$(DESTDIR)/$(PREFIX)/share/help/C/eizelle/methods.page" \
"$(DESTDIR)/$(PREFIX)/share/help/C/eizelle/notes.page" \
"$(DESTDIR)/$(PREFIX)/share/help/C/eizelle/prefs-birth-control.page" \
"$(DESTDIR)/$(PREFIX)/share/help/C/eizelle/prefs-calendar-colors.page" \
"$(DESTDIR)/$(PREFIX)/share/help/C/eizelle/prefs-calendar-layout.page" \
"$(DESTDIR)/$(PREFIX)/share/help/C/eizelle/prefs-menstrual-cycle.page" \
"$(DESTDIR)/$(PREFIX)/share/help/C/eizelle/prefs-password-protection.page" \
"$(DESTDIR)/$(PREFIX)/share/icons/hicolor/16x16/apps/eizelle.png" \
"$(DESTDIR)/$(PREFIX)/share/icons/hicolor/22x22/apps/eizelle.png" \
"$(DESTDIR)/$(PREFIX)/share/icons/hicolor/24x24/apps/eizelle.png" \
"$(DESTDIR)/$(PREFIX)/share/icons/hicolor/256x256/apps/eizelle.png" \
"$(DESTDIR)/$(PREFIX)/share/icons/hicolor/32x32/apps/eizelle.png" \
"$(DESTDIR)/$(PREFIX)/share/icons/hicolor/48x48/apps/eizelle.png" \
"$(DESTDIR)/$(PREFIX)/share/icons/hicolor/512x512/apps/eizelle.png" \
"$(DESTDIR)/$(PREFIX)/share/icons/hicolor/scalable/apps/eizelle.svg" \
"$(DESTDIR)/$(PREFIX)/share/man/man1/eizelle.1.gz"

all : program doc test

program :
	@echo -n "building program..."
	@sed "s/PROGRAM_VERSION/$(VERSION)/" "src/eizelle.py" > "src/eizelle" \
	&& chmod 755 "src/eizelle" \
	&& echo "ok"
	@echo -n "building desktop file..."
	@cp "data/eizelle.desktop.in"  "data/eizelle.desktop" \
	&& echo "Exec=$(PREFIX)/bin/eizelle" >> "data/eizelle.desktop" \
	&& echo "ok"

doc :
	@echo -n "building man page..."
	@sed "s/PROGRAM_VERSION/$(VERSION)/" "data/eizelle.1" | gzip --best - > "data/eizelle.1.gz" \
	&& echo "ok"

test :
	@echo -n "building test suite..."
	@cp "src/eizelletest.py" "src/eizelletest" \
	&& chmod 755 "src/eizelletest" \
	&& echo "ok"

clean :
	@echo -n "cleaning..."
	@rm -f "data/eizelle.1.gz" \
	&& rm -f "src/eizelle" \
	&& rm -f "data/eizelle.desktop" \
	&& rm -f "src/eizelletest" \
	&& echo "ok"

install :
	@echo -n "installing program..."
	@mkdir -p "$(DESTDIR)/$(PREFIX)/bin" \
	&& cp --preserve=mode "src/eizelle" "$(DESTDIR)/$(PREFIX)/bin/eizelle" \
	&& echo "ok"
	@echo -n "install man page..."
	@mkdir -p "$(DESTDIR)/$(PREFIX)/share/man/man1" \
	&& cp "data/eizelle.1.gz" "$(DESTDIR)/$(PREFIX)/share/man/man1" \
	&& echo "ok"
	@echo -n "installing icons..."
	@mkdir -p "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/16x16/apps" \
	&& cp data/icons/16x16/eizelle.png "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/16x16/apps" \
	&& mkdir -p "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/22x22/apps" \
	&& cp data/icons/22x22/eizelle.png "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/22x22/apps" \
	&& mkdir -p "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/24x24/apps" \
	&& cp data/icons/24x24/eizelle.png "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/24x24/apps" \
	&& mkdir -p "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/32x32/apps" \
	&& cp data/icons/32x32/eizelle.png "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/32x32/apps" \
	&& mkdir -p "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/48x48/apps" \
	&& cp data/icons/48x48/eizelle.png "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/48x48/apps" \
	&& mkdir -p "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/256x256/apps" \
	&& cp data/icons/256x256/eizelle.png "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/256x256/apps" \
	&& mkdir -p "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/512x512/apps" \
	&& cp data/icons/512x512/eizelle.png "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/512x512/apps" \
	&& mkdir -p "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/scalable/apps" \
	&& cp data/icons/scalable/eizelle.svg "$(DESTDIR)/$(PREFIX)/share/icons/hicolor/scalable/apps" \
	&& echo "ok"
	@echo -n "installing help files..."
	@mkdir -p "$(DESTDIR)/$(PREFIX)/share/help/C/eizelle" \
	&& cp help/* "$(DESTDIR)/$(PREFIX)/share/help/C/eizelle" \
	&& echo "ok"
	@echo -n "installing gsettings schema..."
	@mkdir -p "$(DESTDIR)/$(PREFIX)/share/glib-2.0/schemas" \
	&& cp "data/org.gnome.eizelle.gschema.xml" "$(DESTDIR)/$(PREFIX)/share/glib-2.0/schemas" \
	&& echo "ok"
	@echo -n "installing desktop file..."
	@mkdir -p "$(DESTDIR)/$(PREFIX)/share/applications" \
	&& cp "data/eizelle.desktop" "$(DESTDIR)/$(PREFIX)/share/applications" \
	&& echo "ok"
	@echo -n "installing appdata..."
	@mkdir -p "$(DESTDIR)/$(PREFIX)/share/appdata" \
	&& cp "data/eizelle.appdata.xml" "$(DESTDIR)/$(PREFIX)/share/appdata" \
	&& echo "ok"

uninstall :
	@echo -n "uninstalling..."
	@rm -f $(FILES) \
	&& rmdir "$(DESTDIR)/$(PREFIX)/share/help/C/eizelle" \
	&& echo "ok"

